
const fs  = require('fs');

const  images = require('images');


let rootpath = 'F:/6点秒杀_好店/05-14/';  //基目录

let originpath = rootpath + 'yasuo';  //图片存放的目录
 
let dest = rootpath + '';  //图片的目标目录

let isImag =  str=>/\.(jpg|png)$/.test(str);


function readdir(path){


	return new Promise((resolve, reject)=>{

		fs.readdir(path,(err, files)=>{

			if(err){
				return reject(err)
			}
			resolve(files)	
		})


	})
}


(async ()=>{

	try{


		let list =  await readdir(originpath);


		for(let v of list){


			console.log(originpath+'/'+v);

			if( isImag(v) ){

				images(originpath+'/'+v).size(750).save(dest+"/"+v, {quality : 100});

			}

		}


	}catch(e){

		console.error(e);

	}


	

})();